package com.chengxiaoxiao.dao.impl;

import com.chengxiaoxiao.dao.ClassesDao;
import com.chengxiaoxiao.domain.Classes;
import com.chengxiaoxiao.utils.db.BeanHandler;
import com.chengxiaoxiao.utils.db.BeanListHandler;
import com.chengxiaoxiao.utils.db.DBAssist;
import com.chengxiaoxiao.utils.db.DBCPUtil;

import java.util.List;

public class ClassesDaoImpl implements ClassesDao {
    private DBAssist da = new DBAssist(DBCPUtil.getDataSource());

    @Override
    public void add(Classes classes) {
        da.update("insert into classes(name,collegeId) values(?,?)",classes.getName(),classes.getCollegeId());
    }

    @Override
    public void update(Classes classes) {
        da.update("update classes set name=?,collegeId=? where id=?",classes.getName(),classes.getCollegeId(),classes.getId());
    }

    @Override
    public void delete(long id) {
        da.update("delete from classes where id=?",id);
    }

    @Override
    public List get() {
        return (List) da.query("select * from classes",new BeanListHandler(Classes.class));
    }

    @Override
    public Classes getbyId(long id) {
        return (Classes) da.query("select * from classes where id=?",new BeanHandler(Classes.class),id);
    }

    @Override
    public List getListPage(int startIndex, int pageSize) {
        return null;
    }
}
